package com.example.test.agent.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @author 小熊猫
 */
@Data
@ApiModel(value = "返回信息封装模型")
public class BaseResult<T> implements Serializable {

    @ApiModelProperty(value = "状态 200代表业务正常执行 500则会在msg中描述失败原因")
    public Integer code;
    @ApiModelProperty(value = "描述")
    public String message;
    @ApiModelProperty(value = "对象")
    public T data;

    public BaseResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public BaseResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static BaseResult success(Object object) {
        return new BaseResult(200, "成功", object);
    }

    public static BaseResult success() {
        return new BaseResult(200, "成功");
    }

    public static BaseResult successMsg(String msg) {
        return new BaseResult(200, msg);
    }

    public static BaseResult successMsg(Object object, String msg) {
        return new BaseResult(200, msg, object);
    }

    public static BaseResult error(Object object) {
        return new BaseResult(500, "失败", object);
    }

    public static BaseResult error() {
        return new BaseResult(500, "失败");
    }

    public static BaseResult errorCode(Integer code) {
        return new BaseResult(code, "失败");
    }

    public static BaseResult errorMsg(String msg) {
        return new BaseResult(500, msg);
    }

    public static BaseResult error(Integer code, String message){
        return new BaseResult(code, message);
    }


    public BaseResult(T data) {
        this.code = 200;
        this.message = "成功";
        this.data = data;
    }


    public BaseResult toJson200() {
        this.code = 200;
        this.message = "成功";
        return this;
    }

    public BaseResult toJson500() {
        this.code = 500;
        this.message = "失败";
        return this;
    }

    public BaseResult toJson500(String msg) {
        this.code = 500;
        this.message = msg;
        return this;
    }
    
    

}
